

#基本捕获语法
try:
    f=open("/home/zjg/py_test/pyth_test/123_test","r",encoding="UTF-8")

except:
    print("出现异常， 没有文件，那就创建一个文件")
    f=open("/home/zjg/py_test/pyth_test/123_test","w",encoding="UTF-8")
finally:#有没有异常都得执行
    f.close()

#捕获指定异常
try:
    print(name)
except NameError as e:
    print(e)

#捕获多个异常
try:
    1/0
    print(name)
except(NameError,ZeroDivisionError) as e:
    print(e)

print("----------")
#捕获所有异常
try:
    # 1/0
    print(name1)
except Exception as e:
    print(e)